﻿using BusinessLogic;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Logic;
using Common;
using System.IO;

namespace AppAdmin.Controllers
{
    public class StylistController : Controller
    {
        //
        // GET: /Stylist/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult SelectShop()
        {
            return View();
        }
        public ActionResult Form()
        {
            StylistLogic bll = new StylistLogic();
            List<PriceConfig> listPriceConfig = bll.GetPriceConfig();

            ViewData["listPriceConfig"] = listPriceConfig; 
            string keyValue = Request.QueryString["keyValue"];

            List<StylelistDetailsInfo> DetailsInfoList = bll.GetStylelistDetailsInfoList(keyValue);
            ViewData["DetailsInfoList"] = DetailsInfoList;
            if (!string.IsNullOrEmpty(keyValue))
            {
                PicLogic pic_bll = new PicLogic();
                var result_data = pic_bll.GetPicListByTypeAndSource(Convert.ToInt32(keyValue), 2);
                ViewData["Piclist"] = result_data;

                var data = new StylistLogic().GetStylistModel(Convert.ToInt32(keyValue));
                List<StylistPrice> StylistPrice = bll.GetStylistPrice(data.Guid);
                ViewData["StylistPrice"] = StylistPrice;
            }
            return View();
        }
        public ActionResult Details()
        {
            StylistLogic bll = new StylistLogic();
            List<PriceConfig> listPriceConfig = bll.GetPriceConfig();

            ViewData["listPriceConfig"] = listPriceConfig;
            string keyValue = Request.QueryString["keyValue"];

            List<StylelistDetailsInfo> DetailsInfoList = bll.GetStylelistDetailsInfoList(keyValue);
            ViewData["DetailsInfoList"] = DetailsInfoList;
            if (!string.IsNullOrEmpty(keyValue))
            {
                PicLogic pic_bll = new PicLogic();
                var result_data = pic_bll.GetPicListByTypeAndSource(Convert.ToInt32(keyValue), 2);
                ViewData["Piclist"] = result_data;

                var data = new StylistLogic().GetStylistModel(Convert.ToInt32(keyValue));
                List<StylistPrice> StylistPrice = bll.GetStylistPrice(data.Guid);
                ViewData["StylistPrice"] = StylistPrice;
            }
            return View();
        }
        

        [HttpGet]
        public ActionResult GetGridJson(Pagination pagination, string keyword, string ShopName)
        {
            try 
            {
                var expression = ExtLinq.True<V_Stylist>();
                expression = expression.And(t => t.Isdelete == 0);
                if (!string.IsNullOrEmpty(keyword))
                {
                    expression = expression.And(t => t.Name.Contains(keyword.Trim()));
                }
                if (!string.IsNullOrEmpty(ShopName))
                {
                    expression = expression.And(t => t.ShopName.Contains(ShopName.Trim()));
                }

                int Total = 0;
                var list = new StylistLogic().getPageDate<V_Stylist, int>(c => new { c.ID, c.Birthday, c.Sex, c.Address, c.Price, c.ShopID, c.Name, c.NickName, c.Height, c.Weight, c.Introduce, c.Addtime, c.AddPerson, c.ModifyDate, c.ModifyPerson, c.Pic, c.Tel, c.IsShow, c.ShopName }, expression, c => c.ID, pagination.page, pagination.rows, out Total);
                pagination.records = Total;
                var data = new
                {
                    rows = list,
                    total = pagination.total,
                    page = pagination.page,
                    records = pagination.records
                };
                return Content(data.ToJson());
            }
            catch (Exception ex)
            { 
            
            }
            return Content("");
        }
        [HttpGet]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = new StylistLogic().GetForm_ShopName(Convert.ToInt32(keyValue));
            return Content(data.ToJson());
        }
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteForm(string keyValue)
        {
            StylistLogic bll = new StylistLogic();
            bll.DelInfo(Convert.ToInt32(keyValue));
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = "删除成功。" }.ToJson());
        }
        public ActionResult Show(string keyValue)
        {
            StylistLogic bll = new StylistLogic();
            bll.Show(Convert.ToInt32(keyValue));
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = "操作成功。" }.ToJson());
        }
        public ActionResult notShow(string keyValue)
        {
            StylistLogic bll = new StylistLogic();
            bll.UnShow(Convert.ToInt32(keyValue));
            return Content(new AjaxResult { state = ResultType.success.ToString(), message = "操作成功。" }.ToJson());
        }
        [HttpGet]
        public ActionResult UploadPic()
        {
            return View();
        }

    }
}
